package com.leo.springbootmultithreadbasic.synchronizedkey.deadlock;

/**
 *
 * @author Leo
 * @version V1.0
 */
public class MainDemo {
    public static void main(String[] args) {
        test();
    }

    /**
     * 测试场景：
     * Synchronized同步代码块时，出现死锁
     *
     */
    public static void test() {
        MyService myService = new MyService();
        Thread threadA = new MyThread(myService);
        ((MyThread) threadA).setUsername("A");
        threadA.start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Thread threadB = new MyThread(myService);
        ((MyThread) threadB).setUsername("B");
        threadB.start();
    }
}
